 
cmake_minimum_required(VERSION 3.13)

project(QtLang)

#add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")

set(CMAKE_C_STANDARD 99) 
set(CMAKE_C_STANDARD_REQUIRED ON) 
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) 
set(CMAKE_CXX_EXTENSIONS OFF) 
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 

#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

set_property(GLOBAL PROPERTY USE_FOLDERS ON) 

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set (QT_LANG_TOP_DIR  ${PROJECT_SOURCE_DIR}      )
set (QT_LANG_BIN_DIR  ${CMAKE_CURRENT_BINARY_DIR})
set (QT_LANG_TOP_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
set (QT_LANG_INC_DIRS ${QT_LANG_TOP_DIR}/         ${QT_LANG_TOP_DIR}/       )

#  Set Target Info
set(CMAKE_INSTALL_PREFIX           ${CMAKE_BINARY_DIR}/install CACHE PATH "Where to install output files")
set(CMAKE_DEBUG_POSTFIX            d                      )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    message(STATUS "64-bit ")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
    message(STATUS "32-bit ")
else()
    message(STATUS "Unknown architecture")
endif()

file(GLOB_RECURSE PROJ_SRCS_LIST   RELATIVE ${QT_LANG_TOP_DIR} ${QT_LANG_TOP_DIR}/src/*.c*)
file(GLOB_RECURSE PROJ_SRCS_FILTER RELATIVE ${QT_LANG_TOP_DIR} ${QT_LANG_TOP_DIR}/src/xxx.c*)
list(REMOVE_ITEM  PROJ_SRCS_LIST            ${PROJ_SRCS_FILTER} )

file(GLOB_RECURSE PROJ_HDRS_LIST   RELATIVE ${QT_LANG_TOP_DIR} ${QT_LANG_TOP_DIR}/src/*.h*)
file(GLOB_RECURSE PROJ_HDRS_FILTER RELATIVE ${QT_LANG_TOP_DIR} ${QT_LANG_TOP_DIR}/src/xxx.h*)
list(REMOVE_ITEM  PROJ_HDRS_LIST            ${PROJ_HDRS_FILTER} )

file(GLOB_RECURSE PROJ_FRMS_LIST   RELATIVE ${QT_LANG_TOP_DIR} ${QT_LANG_TOP_DIR}/src/*.ui*)
file(GLOB_RECURSE PROJ_FRMS_FILTER RELATIVE ${QT_LANG_TOP_DIR} ${QT_LANG_TOP_DIR}/src/xxx.ui*)
list(REMOVE_ITEM  PROJ_FRMS_LIST            ${PROJ_FRMS_FILTER} )

set(SOURCES ${PROJ_SRCS_LIST})
set(HEADERS ${PROJ_HDRS_LIST})
set(FORMS   ${PROJ_FRMS_LIST})

set(RESOURCES src/Lang.qrc)

#qt5_wrap_ui       (${FORMS})
#qt5_add_resources (${RESOURCES})

# ${LIBQT6_LIBRARIES}
set(QT Core Gui Widgets Network WebEngineCore) 

include(cmake/dep_libqt6.cmake)
include(cmake/find_bit7z.cmake)
include(cmake/find_freeglut.cmake)
include(cmake/find_libusb.cmake)
include(cmake/find_libusb_k.cmake)
include(cmake/find_libusb_win32.cmake)
include(cmake/find_libwdi.cmake)
include(cmake/find_sqlite.cmake)
include(cmake/find_openssl.cmake)


find_package(Qt6 REQUIRED ${QT})

source_group(TREE ${QT_LANG_TOP_DIR} FILES ${SOURCES} ${HEADERS} ${FORMS} ${RESOURCES} )

set                        (  QT_LANG_APP           QtLang )
add_executable             (${QT_LANG_APP}          ${SOURCES}    ${HEADERS}    ${FORMS}    ${RESOURCES}    )
target_compile_options     (${QT_LANG_APP} PRIVATE   /Z7     /W4          )
target_compile_definitions (${QT_LANG_APP} PRIVATE                             ${LUA_DEP_DEFS}                  )
target_include_directories (${QT_LANG_APP} PUBLIC   ./src/                     ${LUA_INCLUDE_DIRS}          )
target_link_directories    (${QT_LANG_APP} PUBLIC   ./lib/                     ${LUA_LIBRARY_DIRS}          )
target_link_libraries      (${QT_LANG_APP}          ${LIBQT6_LIBRARIES}        ${LUA_LIBRARIES}             )

set(install_targets ${QT_LANG_APP} )
set(install_hdr_dir include)

install(TARGETS ${install_targets}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
        PUBLIC_HEADER DESTINATION ${install_hdr_dir}
       )

install(FILES     ${PROJ_HDRS_LIST}       DESTINATION ${install_hdr_dir} )
install(DIRECTORY "inc_sub_dir"           DESTINATION ${install_hdr_dir} FILES_MATCHING PATTERN "*.h")
